#!/bin/bash -e

HOST='192.168.2.202'
USER='xcy'
PASSWD='123'
RESULT_DIR='/tmp/result/'
FILE_NAME=$1

[[ -s $FILE_NAME ]] && expect -c '
    set timeout -1;
    spawn scp '$FILE_NAME' '${USER}'@'${HOST}':'$RESULT_DIR''$FILE_NAME'_'$(date -d "today" +"%Y%m%d%H%M")'.log;
    expect {
        "yes/no" {
            send "yes\r"; exp_continue
        }
        "*password:" {
            send '"${PASSWD}\r"'
        }
    };
    expect '${USERS[i]}*' {send "exit\r"};
    expect eof;
' && rm $FILE_NAME

echo "collected end..."
